package cn.tansanqinger.controller.account;

import javax.servlet.http.HttpServletRequest;

import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.tansanqinger.service.account.IUserAccountService;
import cn.tansanqinger.util.PageData;

@Controller
@RequestMapping("/admin/account")
public class AccountTeacherController {

	@Autowired
	private IUserAccountService service;
	
	@RequestMapping("/list5")
	public ModelAndView list5(ModelAndView mv) {
		mv.setViewName("account/list5");
		return mv;
	}
	
	/**
	 * 对学生账号进行过滤，让学生账号的所有首页初始数据都可以从这里查询
	 * @param request
	 * @return
	 */
	@RequestMapping("/selectCondition5")
	public @ResponseBody String selectCondition(HttpServletRequest request) {
		PageData pd = new PageData(request);
		try {
			String keywords = pd.getString("keywords");	//关键词检索条件
			if(null != keywords && !"".equals(keywords)){
				pd.put("keywords", keywords.trim());
			}
			pd = service.selectScreenAccount(pd,1);
			pd.put("code","0");
			pd.put("msg", "查询成功");
			return new ObjectMapper().writeValueAsString(pd);
		} catch (Exception e) {}
		return null;
	}
	
	/**
	 * 对学生账号管理list3编辑进行操作
	 * @param request
	 * @param mv
	 * @return
	 */
	@RequestMapping("/list5_edit")
	public @ResponseBody ModelAndView list3_edit(HttpServletRequest request, ModelAndView mv) {
		PageData pd = new PageData(request);
		//对数据进行填充，然后给表格加以修改的功能
		mv.addObject("user", service.selectId(pd));
		mv.setViewName("account/list5_edit");
		return mv;
	}
	
	/**
	 * 学生账号管理详情进行操作
	 * @param request
	 * @param mv
	 * @return
	 */
	@RequestMapping("/list5_details")
	public @ResponseBody ModelAndView list3_details(HttpServletRequest request, ModelAndView mv) {
		PageData pageData = new PageData(request);
		//对数据进行查询，所有信息不能进行修改，
		//查询报告对账号信息本身进行查询，还有操作账号的数据进行查询
		mv.addObject("user", service.selectId(pageData));
		//
		mv.setViewName("account/list5_details");
		return mv;
	}
	
	/**
	 * 对学生账号进行封号或者解封账号
	 * @param request
	 * @return
	 */
	@RequestMapping("/list5_del")
	public @ResponseBody PageData list3_del(HttpServletRequest request) {
		//PageData pageData = new PageData(request);
		
		return null;
	}
}
